package com.bolt.admin.web.controller;

import com.bolt.admin.common.base.BaseController;
import com.bolt.admin.module.sys.entity.AreaEntity;
import com.bolt.admin.module.sys.service.AreaService;
import com.bolt.common.utils.StrUtil;
import com.bolt.support.ui.tree.vo.UITreeNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * Auto Generate Javadoc
 *
 * @author　米超
 * 日期:2018-02-27 14:20:36
 * 地区信息
 **/
@Controller
@RequestMapping("/admin/sys/area")
public class AreaController extends BaseController<AreaEntity, Long> {

    @Autowired
    private AreaService areaService;


    @RequestMapping(value = "areaTree")
    public String areaTreeIndex(){
        return "/admin/sys/area/areaTree";
    }

    @RequestMapping(value = "getTree")
    @ResponseBody
    public List<UITreeNode> getTree(@RequestParam(name = "id", required = false) String id, @RequestParam Map<String, String> params) {
        boolean loadAllNodes = StrUtil.isEmpty(params.get("loadAllNodes")) ? false : Boolean.parseBoolean(params.get("loadAllNodes"));
        return super.getTreeNodes(areaService, id, loadAllNodes, params);
    }

    @RequestMapping(value = "getAllTree")
    @ResponseBody
    public List<AreaEntity> getAllTreeData(){
        return areaService.findAllCached();
    }


}
